home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Practical Algorithms for Image Analysis
/
Practical Algorithms for Image Analysis.iso
/
CH_2.2
/
HISTRAMP
/
histdistr.c
next >
Wrap
Text File
|
1999-09-11
|
1KB
|
51 lines
/*
* histdistr.c
*
* Practical Algorithms for Image Analysis
*
* Copyright (c) 1997, 1998, 1999 MLMSoftwareGroup, LLC
*/
/* HISTDISTR: function calculates the MODIFIED histogram cumulative
* distribution, that is, from the lowest occupied bin
* to the highest, MINUS 1/2 OF THESE LOWEST AND HIGHEST BINS
* usage: histdistr (hist, nBins, distr)
*
*
*/
int
histdistr (hist, nBins, distr)
long *hist, /* histogram array */
nBins, /* no. of histogram bins */
*distr; /* histogram cumulative distr. array */
{
register long binLow, /* lowest and highest occupied bins */
binHigh, bin; /* histogram bin incrementor */
double total; /* floating point cumulative distr. */
/* find lowest and highest occupied bins */
for (binLow = 0; binLow < nBins; binLow++)
if (hist[binLow] != 0)
break;
for (binHigh = nBins - 1; binHigh >= 0; binHigh--)
if (hist[binHigh] != 0)
break;
/* compute cumulative distribution */
for (bin = 0; bin <= binLow; bin++)
distr[bin] = 0;
total = 0.0;
for (bin = binLow + 1; bin <= binHigh; bin++) {
total += ((hist[bin - 1] + hist[bin]) / 2.0);
distr[bin] = (long) (total + 0.5);
}
for (bin = binHigh + 1; bin < nBins; bin++)
distr[bin] = distr[bin - 1];
return (0);
}